package com.api.shopapi.mapper;

import com.api.shopapi.entity.NursingScheduling;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
@Mapper
public interface NursingSchedulingMapper {

    @Insert("insert into nursing_scheduling " +
            "(NursingSchedulingCode,Type,Day,Time,CreateTime,Status,StaffCode,InstitutionCode) " +
            "values (#{nursingScheduling.NursingSchedulingCode} ,#{nursingScheduling.Type} ,#{nursingScheduling.Day},#{nursingScheduling.Time}," +
            "#{nursingScheduling.CreateTime} ,#{nursingScheduling.Status} ,#{nursingScheduling.StaffCode},#{nursingScheduling.InstitutionCode} )")
    int insert(@Param("nursingScheduling") NursingScheduling nursingScheduling);

    @Update("update nursing_scheduling set Type =#{nursingScheduling.Type} ,Day =#{nursingScheduling.Day},Time =#{nursingScheduling.Time},CreateTime=#{nursingScheduling.CreateTime}," +
            "Status=#{nursingScheduling.Status} ,StaffCode=#{nursingScheduling.StaffCode},InstitutionCode=#{nursingScheduling.InstitutionCode} where NursingSchedulingCode=#{nursingScheduling.NursingSchedulingCode}  ")
    int updateByNursingSchedulingCode(@Param("nursingScheduling") NursingScheduling nursingScheduling);

    @Delete("delete from nursing_scheduling where NursingSchedulingCode=#{nursingSchedulingCode} ")
    int deleteByNursingSchedulingCode(@Param("nursingSchedulingCode") String nursingSchedulingCode);

    @Select("select * from nursing_scheduling where NursingSchedulingCode=#{nursingSchedulingCode} limit 1")
    NursingScheduling getByNursingSchedulingCode(@Param("nursingSchedulingCode") String nursingSchedulingCode);

    @Select("select * from nursing_scheduling where Time=#{time} and InstitutionCode = #{institutionCode} limit 1")
    NursingScheduling getByTime(@Param("time") Date time,@Param("institutionCode")String institutionCode);

    @Select("select * from nursing_scheduling where to_days(Time) = to_days(now()) and InstitutionCode = #{institutionCode} limit 1")
    NursingScheduling getByNowTime(@Param("institutionCode")String institutionCode);

    @Select("select * from nursing_scheduling where InstitutionCode = #{institutionCode} and" +
            " Time between #{startTime} and #{endTime} " +
            " order by Time asc")
    List<NursingScheduling> getListByTime(@Param("institutionCode")String institutionCode, @Param("startTime")String startTime, @Param("endTime")String endTime);


    @Select("select * from nursing_scheduling" +
            " where" +
            " InstitutionCode in (select institutionCode from institution where governmentCode=#{governmentCode}) " +
            " and Time between #{startTime} and #{endTime} " +
            " order by Time asc")
    List<NursingScheduling> listByGovCode(@Param("governmentCode")String governmentCode, @Param("startTime")String startTime, @Param("endTime")String endTime);


}
